package com.xin.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xin.constant.MessageConstant;
import com.xin.entity.Result;
import com.xin.pojo.Setmeal;
import com.xin.service.SetmealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author 夜天
 * @Date 2021/12/19 14:52
 * @Version 1.0.0
 * @description： 移动端套餐管理
 */
@RestController
@RequestMapping("/setmeal")
public class SetMealController {
    @Reference
    private SetmealService setmealService;

    // 查询所有套餐
    @RequestMapping("/")
    public Result getAllSetmeal() {
        try {
            List<Setmeal> list = setmealService.findAll();
            // 获取套餐列表数据成功
            return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS, list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_SETMEAL_LIST_FAIL);
        }
    }

    // 根据 id 查询套餐数据
    @RequestMapping("/findById")
    public Result findById(Integer id) {
        try {
            Setmeal setmeal = setmealService.findById(id);
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}
